package logic

import (
	"context"
	"user/userclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderLogic {
	return &OrderLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *OrderLogic) Order(req *types.OrderRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	order, err := l.svcCtx.OrderRpc.Order(l.ctx, &userclient.OrderRequest{
		GoodId: int64(req.GoodId),
		Price:  int64(req.Price),
		Num:    int64(req.Num),
		Total:  int64(req.Total),
		Title:  req.Title,
		UserId: int64(req.UserId),
	})
	if err != nil {
		return &types.Response{
			Code: "500",
			Msg:  err.Error(),
			Data: nil,
		}, nil

	}
	return &types.Response{
		Code: "200",
		Msg:  "订单创建成功",
		Data: order,
	}, nil

}
